package cn.ecnu.user.controller;

import cn.ecnu.user.pojo.Notification;
import cn.ecnu.user.service.NotificationService;
import cn.ecnu.user.vo.NotificationFrontVo;
import cn.ecnu.user.vo.NotificationVo;
import cn.ecnu.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/notification")
public class NotificationController {

    @Autowired
    private NotificationService notificationService;


    // insert a notification
    @PostMapping("/notify")
    public R notify(@RequestBody NotificationFrontVo vo) {
        notificationService.addNotificationByUid(vo);
        return R.ok();
    }

    // get one's all notification
    @GetMapping("/getNotificationByUid/{uid}")
    public R getNotificationByUid(@PathVariable("uid") Integer uid) {
        List<Notification> notifications = notificationService.getNotificationByUid(uid);
        return R.ok().put("data", notifications);
    }

    // update the notification
    @PostMapping("/update")
    public R updateNotification(@RequestBody NotificationVo vo) {
        notificationService.updateReadByNid(vo);
        return R.ok();
    }
}
